/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {TreeNode}
 */
 var lowestCommonAncestor = function(root, p, q) {
    const parent = function(root,p,q){
      if(root === null || root === p || root === q){
        return root
      }
      let left = parent(root.left,p,q)
      let right = parent(root.right,p,q)
      if(left && right){
        return root
      }
      if(left){
        return left
      }else{
        return right
      }
    }
    return parent(root,p,q)
};